package vip.xiaomoli.idempotent.component;

import org.springframework.util.StringUtils;
import vip.xiaomoli.idempotent.exception.IdempotentException;

public class RequestIDContainer {

    private static final ThreadLocal<String> container = new ThreadLocal<>();

    public static void set(String requestID) {
        container.set(requestID);
    }

    public static String get() {
        String requestID = container.get();
        if (StringUtils.isEmpty(requestID)) throw new IdempotentException("RequestID is not in the RequestIDContainer!");
        return requestID;
    }

    public static void remove() {
        container.remove();
    }

}
